//
//  JianTingCell.swift
//  JianTingSwift
//
//  Created by zhibao on 2024/11/7.
//

import UIKit
class JianTingCell: UITableViewCell {
    fileprivate var nameLabel = UILabel()
    fileprivate var durationLabel = UILabel()
    fileprivate var createTimeLabel = UILabel()
    fileprivate var audioImgView = UIImageView(image: UIImage(systemName: "waveform"))
    fileprivate var selectBtn:UIButton!
    var duoxuanLabel:UILabel!
    @objc var doneBlock:RightDoneBlock?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = UIColor.clear
        self.contentView.backgroundColor = UIColor.clear
        let bgView = UIView()
        bgView.backgroundColor = MYColor.color(withHexString: "#25282D", alpha: 0.8)
        self.contentView.addSubview(bgView)
        bgView.layer.cornerRadius = pixw(p:15)
        bgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:15))
            make.top.equalTo(pixw(p:10))
            make.right.equalTo(pixw(p:-15))
//            make.height.equalTo(pixw(p:70))
            make.bottom.equalTo(0)
        }
        
        audioImgView.tintColor = UIColor.white
        bgView.addSubview(audioImgView)
        audioImgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:15))
            make.centerY.equalTo(bgView)
        }
        
        selectBtn = UIButton(type: .custom)
        selectBtn.setImage(UIImage(systemName: "square.and.arrow.up.fill"), for: .normal)
        selectBtn.tintColor = UIColor.white
        selectBtn.addTarget(self, action: #selector(selectBtnCilck), for: .touchUpInside)
        bgView.addSubview(selectBtn)
        selectBtn.snp.makeConstraints { make in
            make.right.equalTo(pixw(p:-15));
            make.centerY.equalTo(bgView);
            make.width.height.equalTo(pixw(p:40));
        }
        
        duoxuanLabel = UILabel()
        duoxuanLabel.text = ""
        duoxuanLabel.layer.cornerRadius = pixw(p:10)
        duoxuanLabel.font = MY_SCALE_RegularFONT(12)
        duoxuanLabel.layer.borderColor = UIColor.white.cgColor
        duoxuanLabel.layer.borderWidth = pixw(p:0.5)
        duoxuanLabel.clipsToBounds = true
        duoxuanLabel.textAlignment = .center
        duoxuanLabel.isHidden = true
        duoxuanLabel.textColor = MYColor.color(withHexString: "#FC2F55")
        bgView.addSubview(duoxuanLabel)
        duoxuanLabel.snp.makeConstraints { make in
            make.centerY.equalTo(audioImgView);
            make.width.height.equalTo(pixw(p:20));
            make.right.equalTo(bgView).offset(pixw(p:-15));
        }
        
        nameLabel.text = "20241110_audio.mp3"
        nameLabel.font = MY_SCALE_RegularFONT(13)
        nameLabel.textColor = MYOrange
        bgView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:55))
            make.top.equalTo(pixw(p:15))
            //make.right.equalTo(selectBtn.snp.left).offset(pixw(p:-15))
        }
        
        durationLabel.text = "时长:100s"
        durationLabel.font = MY_SCALE_LightFONT(11)
        durationLabel.textColor = .white
        bgView.addSubview(durationLabel)
        durationLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel.snp.right).offset(pixw(p: 3))
            make.centerY.equalTo(nameLabel)
        }
        
        createTimeLabel.text = "2024-10-32 19:33:33"
        createTimeLabel.font = MY_SCALE_RegularFONT(11)
        createTimeLabel.textColor = MYColor.color(withHexString: "999999")
        bgView.addSubview(createTimeLabel)
        createTimeLabel.snp.makeConstraints { make in
            make.left.right.equalTo(nameLabel)
            make.top.equalTo(nameLabel.snp.bottom).offset(pixw(p:7))
            make.bottom.equalTo(bgView).offset(pixw(p:-15))
        }
    }
    
    // 0 显示分享  1显示文件夹
    func updata(dic:[String:Any],selectType:NSString = "0"){
        selectBtn.isHidden = false
        duoxuanLabel.isHidden = true
        if selectType == "0" {
            selectBtn.setImage(UIImage(systemName: "square.and.arrow.up.fill"), for: .normal)
        }else{
            selectBtn.setImage(UIImage(named: "com_right"), for: .normal)
        }
        nameLabel.text = dic["title"] as? String
        //时长
        
        createTimeLabel.text = dic["startTime"] as? String
        durationLabel.text = "时长:\(String(describing: dic["duration"]!))s"
    }
    
    func updata(dic:[String:String],num:Int = 0) {
        selectBtn.isHidden = true
        duoxuanLabel.isHidden = false
        if(num > 0){
            duoxuanLabel.text = "\(num)"
            duoxuanLabel.backgroundColor = UIColor.white
        }else{
            duoxuanLabel.text = ""
            duoxuanLabel.backgroundColor = MYColor.color(withHexString: "35393F")
        }
        nameLabel.text = dic["text"]
        createTimeLabel.text = "\(String(describing: dic["create_date"]))    \(String(describing: dic["time"]))"
    }
    
    @objc func selectBtnCilck(){
        if((self.doneBlock) != nil){
            self.doneBlock!()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
